syntax = "proto3";

package kuma.observability.v1;

option go_package = "observability/mads/v1";

import "envoy/service/discovery/v3/discovery.proto";
import "google/api/annotations.proto";
import "validate/validate.proto";

// Monitoring Assignment Discovery Service (MADS).
//
// xDS API that is meant for consumption by monitoring systems, e.g. Prometheus.
service MonitoringAssignmentDiscoveryService {
  // GRPC
  rpc DeltaMonitoringAssignments(
      stream envoy.service.discovery.v3.DeltaDiscoveryRequest)
      returns (stream envoy.service.discovery.v3.DeltaDiscoveryResponse) {}
  rpc StreamMonitoringAssignments(
      stream envoy.service.discovery.v3.DiscoveryRequest)
      returns (stream envoy.service.discovery.v3.DiscoveryResponse) {}
  // HTTP
  rpc FetchMonitoringAssignments(envoy.service.discovery.v3.DiscoveryRequest)
      returns (envoy.service.discovery.v3.DiscoveryResponse) {
    option (google.api.http).post = "/v3/discovery:monitoringassignments";
    option (google.api.http).body = "*";
  }
}

// MADS resource type.
//
// Describes a group of targets on a single service that need to be monitored.
message MonitoringAssignment {
  // Mesh of the dataplane.
  //
  // E.g., `default`
  string mesh = 2 [ (validate.rules).string = {min_bytes : 1} ];

  // Identifying service being monitored.
  //
  // E.g., `backend`
  string service = 3 [ (validate.rules).string = {min_bytes : 1} ];

  // List of targets that need to be monitored.
  repeated Target targets = 4;

  // Describes a single target that needs to be monitored.
  message Target {
    // Dataplane name.
    //
    // E.g., `backend-01`
    string name = 1 [ (validate.rules).string = {min_bytes : 1} ];

    // Scheme on which to scrape the target.
    // E.g., `http`
    string scheme = 2 [ (validate.rules).string = {min_bytes : 1} ];

    // Address (preferably IP) for the service
    // E.g., `backend.svc` or `10.1.4.32:9090`
    string address = 3 [ (validate.rules).string = {min_bytes : 1} ];

    // Optional path to append to the address for scraping
    // E.g., `/metrics`
    string metrics_path = 4;

    // Arbitrary labels associated with that particular target.
    //
    // E.g.,
    // `{
    //    "commit_hash" : "620506a88",
    //  }`.
    map<string, string> labels = 5;
  }

  // Arbitrary Labels associated with every target in the assignment.
  //
  // E.g., `{"team": "infra"}`.
  map<string, string> labels = 5;
}
